package server.version;

import server.RequestProcessor;
import server.loader.ServletLoader;

import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created by louisyuu on 2020/4/2 上午11:03
 * <p>
 * <p>
 * 完成Minicat 3.0版本
 * 需求：可以请求动态资源（Servlet）
 */
public class VersionThreeMultiThreadStarter implements VersionStater {


    @Override
    public void start() throws Exception {

        // 加载解析相关的配置，web.xml
        new ServletLoader().loadLocalServlet();

        ServerSocket serverSocket = new ServerSocket(port);
        System.out.println("=====>>>Minicat start on port：" + port);

        //多线程改造（不使用线程池）
        while (true) {
            Socket socket = serverSocket.accept();
            RequestProcessor requestProcessor = new RequestProcessor(socket, ServletLoader.servletMap);
            requestProcessor.start();
        }


    }
}
